#ifndef PARAMETERSETTINGS_H
#define PARAMETERSETTINGS_H

#include <QWidget>
#include "common/common.h"
#include "myserialport/spscaleadaptor.h"

namespace Ui {
class ParameterSettings;
}

class ParameterSettings : public QWidget
{
    Q_OBJECT

public:
    explicit ParameterSettings(QWidget *parent = 0);
    ~ParameterSettings();

    enum{
        TAB_WEIGHING = 0,
        TAB_CALIBRATE,
        TAB_MODE,
        TAB_SYSTEM,
        TAB_COMMUNICATION
    };
    enum{
        UNIT_KG = 0,
        UNIT_G,
        UNIT_JIN,
        UNIT_LB
    };

    enum{
        DECI_0 = 0,
        DECI_1,
        DECI_2,
        DECE_3
    };

    enum{
        DIVI_1 = 0,DIVI_2,DIVI_3,DIVI_4,DIVI_5,DIVI_6,DIVI_7,DIVI_8,DIVI_9,DIVI_10
    };

    enum{
        ZERO_1 = 0,ZERO_2,ZERO_3,ZERO_4,ZERO_5,ZERO_6
    };

//    static const char* WEIGHING_GROUP;
//    static const char* WEIGHING_UNIT;
//    static const char* WEIGHING_DECI;
//    static const char* WEIGHING_MAX;
//    static const char* WEIGHING_DIVI;
//    static const char* WEIGHING_ZERO;

//    static const char* CALI_GROUP;
//    static const char* CALI_AUTOZEROTRACE_SW;
//    static const char* CALI_AUTOZERORANGE;
//    static const char* CALI_BOOTAUTOZERO_SW;
//    static const char* CALI_BOOTAUTORANGE;

    static const char* MODE_GROUP;
    static const char* MODE_USEMODE;
    static const char* MODE_CHECKMODE;
    static const char* MODE_CHECKEDPAUSE_SW;
    static const char* MODE_AUTOUSBCOPY;
    static const char* MODE_AUTOPRINT_SW;
    static const char* MODE_PRINTFMT;

    static const char* COM1_GROUP;
    static const char* COM2_GROUP;
    static const char* BAUDRATE;
    static const char* STOPBITS;
    static const char* FLOWCTRL;
    static const char* DATABITS;
    static const char* PARITY;
    static const char* COMMUNI_GROUP;
    static const char* COMMUNI_SERVER;
    static const char* COMMUNI_PORT;
    static const char* COMMUNI_IP;


//    static QString getUnit();
//    static QString getMax();
    static QVariant getSettingValue(const QString& setName,const QVariant& defltValue = QVariant(),const QString& groupName="",
                                   const QString& fileName = DIR_SETTINGS);
    static void saveSettingValue(const QString& setName,const QVariant& Value,const QString& groupName="",
                                 const QString& fileName = DIR_SETTINGS);
    static void saveSettingValue(const QStringList& setName,const QVariantList& ValueList,const QString& groupName="",
                                 const QString& fileName = DIR_SETTINGS);

    static int getUseMode();
    static int getCheckMode();
    static int getCheckPauseMode();
    static bool getAutoUsbCopySw();

    void lightBtn(int index);

private slots:
    void on_btn_back_clicked();

    void on_btn_weighing_clicked();

    void on_btn_calibrate_s_clicked();

    void on_btn_mode_clicked();

    void on_btn_commu_clicked();

    void on_btn_calibrate_clicked();

    void on_backlightSld_valueChanged(int);

    void on_btn_setDatetime_clicked();

    void on_btn_next_clicked();

    void on_chk_mousecursor_clicked();
    void onTabBarChanged(int);

    void onMaxClicked();
    bool onSetMax(QString);
    bool onSetUnit(int);
    bool onSetDeci(int);
    void onUpdateDeci();
    bool onSetDivide(int);
    bool onSetZero(int);
    void onErrTimeOut();
    void onSetSuccess();
    void onSetAutoZT(int);
    void onSetAutoSZR(int);

    void onUseModeChanged(int);
    void onCheckModeChanged(int);
    void onCheckPauseChanged(int);
    void onAutoUsbCopyChanged(int);

    void onSetCom1();
    void onSetCom2();

    void onSetServer();
    void onSetNetwork();

    void on_btn_system_clicked();

private:
    Ui::ParameterSettings *ui;
    void initTabWeighing();
    void initTabCalibration();
    void initTabMode();
    void initTabCommunication();
    void initTabSystem();
    QTimer* mErrTimer;
    void startErrTimer();
};

#endif // PARAMETERSETTINGS_H
